﻿using System;
using System.Collections.Generic;
using EmailJabber.EmailJabber.Core.Entities;
using EmailJabber.Logic.Commands.Base;
using EmailJabber.Logic.Logic.BusinessLogic;

namespace EmailJabber.Logic.Commands
{
    public class LogSearchCommand:CommandBase
    {
     

        protected override string GetDecription()
        {
            return "Search in log entries";
        }

        protected override Guid GetId()
        {
            return new Guid("64264BE5-1E6E-4E0F-B256-A83FEE563CF7");
        }


        protected override void ExecuteSafe(MessageIM comnd)
        {
            List<LogEntry> entries = DAL.DAL.Instance.Search(comnd.Body);
            BL.Instance.Send(MessageIM.GetReply("-= Search result =-",comnd));
            foreach (LogEntry logEntry in entries)
            {
                BL.Instance.Send(MessageIM.GetReply(" * ",comnd));
                BL.Instance.Send(MessageIM.GetReply("Time:" + logEntry.Time + Environment.NewLine + logEntry.Extra,comnd));
                
            }
            BL.Instance.Send(MessageIM.GetReply("----   the end   ----",comnd));
        }
    }
}